package com.pshcp.tool;

import com.framework.util.DateUtil;
import com.framework.util.JwtUtil;
import com.framework.util.SystemUtil;
import com.pshcp.domain.model.Session;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: TODO
 * @Author: xiaoche
 * @Date: 2022/11/3 09:58
 */
public class SessionTool {

    public static Session buildLonginSession(JwtUtil jwtUtil, Integer terminal, Long userId) {
        Session session = new Session();
        session.setId(SystemUtil.getId());
        session.setBizStatus(0);
        session.setTerminal(terminal);
        session.setSessionRefreshTime(DateUtil.currDate());
        session.setUserId(userId);
        Map<String, String> claims = new HashMap<>();
        claims.put("id", String.valueOf(session.getId()));
        claims.put("terminal", String.valueOf(terminal));
        claims.put("userId", String.valueOf(userId));
        String token = jwtUtil.buildToken(claims);
        session.setToken(token);
        return session;
    }
}
